package com.hzya.frame.webservice.cxfclient.controller;

import com.hzya.frame.utils.help.WebServiceHelper;
import com.hzya.frame.webservice.cxfserver.service.IOrderWebService;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

import javax.xml.namespace.QName;
import java.net.URL;

/**
 * @description:
 * @author: gjh
 * @Date Created in 2018/8/10 15:11
 */
public class Test {

    /**
     *
     * 远程调用WebService
     *
     * @param methodName    方法类型
     * @param param         参数
     * @return
     * @throws Exception
     */
    public static Object[] routeServer(String methodName,Object param) throws Exception{
        String url = "http://127.0.0.1:8080/maven_frame_easyui/webservice/orderWebService?wsdl";
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();    // 策略
        httpClientPolicy.setConnectionTimeout( 36000 );    //连接超时
        httpClientPolicy.setAllowChunking( false );
        httpClientPolicy.setReceiveTimeout( 10000 );       //接收超时
        Client client = dcf.createClient(url);
        HTTPConduit http = (HTTPConduit) client.getConduit();
        http.setClient(httpClientPolicy);
        return client.invoke(methodName, param);

    }

    public static void main(String[] args) throws Exception {
        IOrderWebService orderWebService = WebServiceHelper.getInterFace();
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        URL url= new URL("http://127.0.0.1:8080/maven_frame_easyui/webservice/orderWebService?wsdl");
        Client client = dcf.createClient(url);
        Object[] o = routeServer("sayHello", "xbz");//client.invoke("sayHello", "xbz");
        System.out.println(o[0]);
        System.out.println("1231");
    }

}
